home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TeX 1995 July
/
TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO
/
macros
/
latex209
/
contrib
/
slatex
/
helpers.ss
< prev
next >
Wrap
Text File
|
1993-11-07
|
4KB
|
123 lines
;helpers.ss
;SLaTeX Version 1.99
;Helpers for SLaTeX
;(c) Dorai Sitaram, Dec. 1991, Rice University
(define set-keyword
(lambda (x)
;add token x to the keyword database
(if (member-token x keyword-tokens) 'skip
(begin
(set! constant-tokens (remove-token! x constant-tokens))
(set! variable-tokens (remove-token! x variable-tokens))
(set! keyword-tokens (cons x keyword-tokens))))))
(define set-constant
(lambda (x)
;add token x to the constant database
(if (member-token x constant-tokens) 'skip
(begin
(set! keyword-tokens (remove-token! x keyword-tokens))
(set! variable-tokens (remove-token! x variable-tokens))
(set! constant-tokens (cons x constant-tokens))))))
(define set-variable
(lambda (x)
;add token x to the variable database
(if (member-token x variable-tokens) 'skip
(begin
(set! keyword-tokens (remove-token! x keyword-tokens))
(set! constant-tokens (remove-token! x constant-tokens))
(set! variable-tokens (cons x variable-tokens))))))
(define set-special-symbol
(lambda (x transl)
;add token x to the special-symbol database with
;the translation transl
(let ((c (assoc-token x special-symbols)))
(if c (set-cdr! c transl)
(set! special-symbols
(cons (cons x transl) special-symbols))))))
(define unset-special-symbol
(lambda (x)
;disable token x's special-symbol-hood
(set! special-symbols
(rem! (lambda (c) (token=? (car c) x)) special-symbols))))
(define texify
(lambda (s)
;create a tex-suitable string out of token s
(list->string (texify-aux s))))
(define texify-data
(lambda (s)
;create a tex-suitable string out of the data token s
(let loop ((l (texify-aux s)) (r '()))
(if (null? l) (list->string (reverse! r))
(let ((c (car l)))
(loop (cdr l)
(if (char=? c #\-) (append! (list #\$ c #\$) r)
(cons c r))))))))
(define texify-aux
(let* ((arrow (string->list "-$>$"))
(arrow-lh (length arrow)))
(lambda (s)
;return the list of tex characters corresponding to token s
(let* ((sl (string->list s))
;some extra context-sensitive prettifying could go here?!
(texified-sl
(append-map! (lambda (c) (string->list (tex-analog c)))
sl)))
(ormapcdr
(lambda (d)
(if (list-prefix? arrow d)
(let ((to (string->list "$\\to$")))
(set-car! d (car to))
(set-cdr! d (append (cdr to)
(list-tail d arrow-lh)))))
#f)
texified-sl)
texified-sl))))
(define display-begin-sequence
(lambda (out)
(display* out "\\" *code-env-spec* "%" eoln)))
(define display-end-sequence
(lambda (out)
(display* out "\\end" *code-env-spec* "{}")))
(define display-tex-char
(lambda (c p)
(display (if (char? c) (tex-analog c) c) p)))
(define display-space
(lambda (s p)
(cond ((eq? s &plain-space) (display #\space p))
((eq? s &init-plain-space) (display #\space p))
((eq? s &init-space) (display "\\HL " p))
((eq? s &paren-space) (display "\\PRN " p))
((eq? s &bracket-space) (display "\\BKT " p))
((eq? s "e-space) (display "\\QUO " p))
((eq? s &inner-space) (display "\\ " p)))))
(define display-tab
(lambda (tab p)
(cond ((eq? tab &set-tab) (display "\\=" p))
((eq? tab &move-tab) (display "\\>" p)))))
(define display-notab
(lambda (notab p)
(cond ((eq? notab &begin-string) (display "\\dt{" p))
((eq? notab &end-string) (display "}" p)))))
(define display-token
(lambda (s typ p)
(cond ((eq? typ 'syntax) (display* p "\\sy{" (texify s) #\}))
((eq? typ 'variable) (display* p "\\va{" (texify s) #\}))
((eq? typ 'constant) (display* p "\\cn{" (texify s) #\}))
((eq? typ 'data) (display* p "\\dt{" (texify-data s) #\}))
(else (lerror 'display-token)))))